package com.fengwan.wastesort

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.Navigation
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.setupWithNavController
import com.fengwan.wastesort.ui.activity.SearchActivity
import com.fengwan.wastesort.utils.StatusBarUtils
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.xuexiang.xui.utils.ResUtils
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.toast

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBarUtils.setStatusBarColor(this, ResUtils.getColor(R.color.colorPrimaryDark), true)
        setContentView(R.layout.activity_main)

        val controller: NavController =
            (supportFragmentManager.findFragmentById(R.id.nav_fragment) as NavHostFragment).navController
        NavigationUI.setupWithNavController(bnv_view, controller)

//        bnv_view.setupWithNavController(Navigation.findNavController(this, R.id.nav_fragment))

        initView(savedInstanceState)
    }

    private fun initView(savedInstanceState: Bundle?) {
        setSupportActionBar(toolbar)
        initToolbar()
//        supportActionBar?.also {
//            it.title = "垃圾分类"
//            it.setDisplayShowTitleEnabled(true)
//        }
    }

    private fun initToolbar() {
        toolbar_comm
            .setTitle("垃圾查询")
            .setIvRight(R.drawable.ic_search_black_36dp) {
                startActivity(Intent(this, SearchActivity::class.java))
//                toast("查询被点击啦！")
//                Navigation.findNavController(this, R.id.nav_fragment).navigate(R.id.searchActivity)
            }
    }

    override fun onSupportNavigateUp(): Boolean {
//        return NavigationUI.navigateUp(Navigation.findNavController(this, R.id.nav_fragment), bnv_view)
        return Navigation.findNavController(this, R.id.nav_fragment).navigateUp()
    }

//    override fun onNavigateUp(): Boolean {
//        return onSupportNavigateUp()
//    }

    override fun onBackPressed() {
        super.onBackPressed()
    }

}
